from public import view_person

from pylib import models
from pylib import web

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class AddPerson(web.BaseHandler):
  @web.transaction_with_retries
  def AddPerson(self):
    person = models.Person()
    person.put(request=self.request)
    identity = models.Identity(parent=person,
                               person=person,
                               name=self.request.get('name'))
    identity.put(request=self.request)
    return person

  @web.valid_xsrf_token_required
  def post(self):
    person = self.AddPerson()
    self.internal_redirect(view_person.ViewPerson(), person.key())


application = webapp.WSGIApplication([('.*', AddPerson)])

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
